package edu.webarchitechture.bank.ejb3.services;

import edu.webarchitechture.bank.ejb3.domain.User;
import org.hibernate.Session;

import java.util.List;

/**
 * UserManagerDAO.
 *
 * @author Inoka Dissanayaka.
 */
public class UserManagerDAO {

    Session session;

    public UserManagerDAO(Session session) {
        this.session = session;
    }

    public User getUserById(Long userId) {
        return (User) session.get(User.class, userId);
    }

    @SuppressWarnings("unchecked")
    public List<User> getAllUsers() {
        return session.createCriteria(User.class).list();
    }

    public void saveUser(User user) {
        session.merge(user);
    }

    public void removeUser(User user) {
        session.delete(user);
    }
}
